<script type="text/javascript" charset="utf-8">
	function updateNameField()
	{
		var first_name = $("#User_first_name").val();
		var last_name = $("#User_last_name").val();
		var $input = $("#User_name");
		$input.find('> option:eq(0)').text(first_name + ' ' + last_name);
		$input.find('> option:eq(1)').text(last_name + ' ' + first_name);
		$input.find('> option:eq(2)').text(first_name);
		$input.find('> option:eq(3)').text(last_name);
		if(first_name!='' && last_name!='') $input.parent().slideDown('fast');
		else $input.parent().slideUp('fast');
	}
	function submitName(_trigger)
	{
		$.ajax({
			url:$(_trigger).attr('href'),
			context:$(_trigger),
			type:'POST',
			data:$('#user-form').serialize(),
			success:function(data) {
				$content_div = $(this).parent().parent().parent().parent();
				$content_div.html("").hide().prev().show();
				$content_div.prev().children(".itemSuccess").fadeIn("fast").delay(2000).fadeOut("fast");
			}
		});

		return false;
	}
</script>
<div class='pvm phs '>
	<div class="left">Họ và tên</div>
	<div style="margin-left:200px;">
		<?php $form=$this->beginWidget('CActiveForm', array(
			'id'=>'user-form',
			'enableAjaxValidation'=>false,
		)); ?>
			<div>
				<b><?php echo $form->label($model, 'first_name') ?>:</b>
				<?php echo $form->textField($model, 'first_name', array('onkeyup'=>'updateNameField()')); ?>

				<b><?php echo $form->label($model, 'last_name') ?>:</b>
				<?php echo $form->textField($model, 'last_name', array('onkeyup'=>'updateNameField()')); ?>
			</div>

			<div class="row <?php echo ($model->first_name!='' && $model->last_name!='') ? "":"hide" ?>">
		        <?php echo $form->label($model,'name'); ?>
		        <?php echo $form->dropDownList(
		        	$model,
		        	'name',
		        	array(
		        		'0'=>$model->first_name . ' ' . $model->last_name, 
		        		'1'=>$model->last_name . ' ' . $model->first_name,
		        		'2'=>$model->first_name,
		        		'3'=>$model->last_name
		        	)); ?>
		    </div>

		    <?php echo CHtml::link(Yii::t('common','Cập nhật'), array('name'), array('onclick'=>'return submitName(this)','class'=>'g-button g-button-submit')); ?>
			<input type="button" class="g-button buttonCancel" value="<?php echo Yii::t('common','Hủy thay đổi') ?>">
		<?php $this->endWidget(); ?>
	</div>
</div>